<template>
  <div class="container">
    <!--  主题内容标题   -->
    <div class="flex contain-header">
      <div class="contain-title">我的收藏</div>
    </div>

    <!--  表格头部标签页  -->
    <div class="tag-vedio">
      <a-tabs default-active-key="1" @change="callback">
        <!--    资料      -->
        <a-tab-pane key="1" tab="资料" class="file">
          <a-list :grid="{ gutter: 34, column: 4 }" :data-source="materialList" :pagination="materialPagination">
            <a-list-item slot="renderItem" slot-scope="item, index" class="column-space">
              <div class="list-item">
                <a-list-item-meta>
                  <div slot="title" class="header">
                    <div>
                      <img :src="'http://zctuchuang.oss-cn-shenzhen.aliyuncs.com/'+item.resourceImage"  class="image">
                      <img src="../../assets/hot.png" class="hot-img">
                    </div>
                    <div class="item-title">
                      <template v-if="item.isCollected">
                        <div class="title-text" :title="item.resourceName">{{ item.resourceName }}</div>
                        <div class="flex collect" @click="cancelCollect(item)">
                          <a-icon type="star" theme="filled" :style="{color: '#1bcbb4'}" class="icon-star"/>
                          <span class="collect-text" :style="{color: '#1bcbb4'}">收藏</span>
                        </div>
                      </template>
                      <template v-else>
                        <div class="title-text title-width" :title="item.resourceName">{{ item.resourceName }}</div>
                        <div class="flex collect">
                          <a-icon type="star"  class="icon-star"/>
                          <span class="collect-text">收藏</span>
                        </div>
                      </template>
                    </div>
                  </div>
                </a-list-item-meta>
                <div class="decoration">
                  <div>
                    <p class="detail-style">{{item.resourceDesc}}</p>
                  </div>
                  <div class="public-time">
                    <span>{{item.createTime}}</span>
                  </div>
                </div>
                <div class="flex item-footer">
                  <div class="footer-presenter">
                    <span>发布人：</span>
                    <span>{{item.resourceUserName}}</span>
                  </div>
                  <div>
                    <template v-if="item.isFollowed">
                      <div @click="cancelFollowed(item)">
                        <span><a-icon type="heart" theme="filled" style="color: #fa3d3d"/></span>
                        <span class="cursor-hover" style="color: #fa3d3d">关注</span>
                      </div>
                    </template>
                    <template v-else>
                      <span><a-icon type="heart"/></span>
                      <span>关注</span>
                    </template>
                  </div>
                </div>
              </div>
            </a-list-item>
          </a-list>
        </a-tab-pane>
        <!--   课件     -->
        <a-tab-pane key="2" tab="课件" class="kejian" force-render>
          <a-list :grid="{ gutter: 34, column: 3 }" :data-source="coursewareList" :pagination="coursewarePagination">
            <a-list-item slot="renderItem" slot-scope="item, index" class="column-space">
              <template>
                <div class="list-item">
                  <a-list-item-meta>
                    <div slot="title" class="flex header">
                      <div>
                        <img :src="'http://zctuchuang.oss-cn-shenzhen.aliyuncs.com/'+item.resourceImage" class="image">
                        <img src="../../assets/hot.png" class="hot-img">
                      </div>
                      <div class="item-title-live">
                        <div class="title-text-live" :title="item.resourceName">{{ item.resourceName }}</div>
                        <div class="footer-presenter-live">
                          <span>发布人：</span>
                          <span>{{item.resourceUserName}}</span>
                        </div>
                      </div>
                    </div>
                  </a-list-item-meta>
                  <div class="flex item-footer">
                    <div>
                      <span>上传时间： </span>
                      <span>{{item.createTime}}</span>
                    </div>
                    <div class="flex">
                      <div>
                        <template v-if="item.isFollowed">
                          <div @click="cancelFollowed(item)">
                            <span><a-icon type="heart" theme="filled" style="color: #fa3d3d"/></span>
                            <span class="cursor-hover" style="color: #fa3d3d">关注</span>
                          </div>
                        </template>
                        <template v-else>
                          <span><a-icon type="heart"/></span>
                          <span>关注</span>
                        </template>
                      </div>
                      <div class="flex margin-live">
                        <template v-if="item.isCollected">
                          <div class="flex collect" @click="cancelCollect(item)">
                            <a-icon type="star" theme="filled" :style="{color: '#1bcbb4'}" class="icon-star"/>
                            <span class="collect-text" :style="{color: '#1bcbb4'}">收藏</span>
                          </div>
                        </template>
                        <template v-else>
                          <div class="flex collect">
                            <a-icon type="star"  class="icon-star"/>
                            <span class="collect-text">收藏</span>
                          </div>
                        </template>
                      </div>
                    </div>
                  </div>
                </div>
              </template>
            </a-list-item>
          </a-list>
        </a-tab-pane>
        <!--   软件     -->
        <a-tab-pane key="3" tab="软件" class="software" force-render>
          <a-list :grid="{ gutter: 34, column: 1 }" :data-source="softwareList" :pagination="softwarePagination">
            <a-list-item slot="renderItem" slot-scope="item, index" class="column-space">
              <template>
                <div class="list-item">
                  <a-list-item-meta>
                    <div slot="title" class="flex header">
                      <div>
                        <img :src="'http://zctuchuang.oss-cn-shenzhen.aliyuncs.com/'+item.resourceImage" alt="vedio" class="image">
                        <img src="../../assets/hot.png" class="hot-img">
                      </div>
                      <div class="item-title-live">
                        <div class="flex flex-between">
                          <div class="title-text-live" :title="item.resourceName">
                            {{ item.resourceName }}
                          </div>
                        </div>
                        <div class="footer-presenter-live">
                          <span>发布人：</span>
                          <span>{{item.resourceUserName}}</span>
                        </div>
                      </div>
                    </div>
                  </a-list-item-meta>
                  <div class="flex item-footer">
                    <div>
                      <span>上传时间： </span>
                      <span>{{item.createTime}}</span>
                    </div>
                    <div class="flex">
                      <div class="flex margin-live">
                        <template v-if="item.isCollected" @click="cancelCollect(item)">
                          <div class="flex collect" >
                            <a-icon type="star" theme="filled" :style="{color: '#1bcbb4'}" class="icon-star"/>
                            <span class="collect-text" :style="{color: '#1bcbb4'}">收藏</span>
                          </div>
                        </template>
                        <template v-else>
                          <div class="flex collect">
                            <a-icon type="star"  class="icon-star"/>
                            <span class="collect-text">收藏</span>
                          </div>
                        </template>
                      </div>
                    </div>
                  </div>
                </div>
              </template>
            </a-list-item>
          </a-list>
        </a-tab-pane>
      </a-tabs>
    </div>
  </div>
</template>

<script>
  import {getUserCollectList} from "@/api";
  import {cancelCollectResource, cancelFollowResource} from "../../api";

  export default {
    name: "Favorites.vue",
    data() {
      return {
        materialPagination: {
          total: 100,
          defaultPageSize: 10,
          showTotal: total => `共 ${total} 条数据`,
          showQuickJumper: true,
          showSizeChanger: true,
          pageSizeOptions: ['5', '10', '15', '20'],
          onChange:(page,pageSize)=>this.getMaterialsList(page,pageSize),//点击页码事件
        },
        coursewarePagination: {
          total: 100,
          defaultPageSize: 10,
          showTotal: total => `共 ${total} 条数据`,
          showQuickJumper: true,
          showSizeChanger: true,
          pageSizeOptions: ['5', '10', '15', '20'],
          onChange:(page,pageSize)=>this.getCoursewaresList(page,pageSize),//点击页码事件
        },
        softwarePagination: {
          total: 100,
          defaultPageSize: 10,
          showTotal: total => `共 ${total} 条数据`,
          showQuickJumper: true,
          showSizeChanger: true,
          pageSizeOptions: ['5', '10', '15', '20'],
          onChange:(page,pageSize)=>this.getSoftwaresList(page,pageSize),//点击页码事件
        },
        coursewareList: [],
        softwareList: [],
        materialList: []

      }
    },
    created() {
      //获取资料列表
      this.getMaterialsList()
      //获取课件列表
      this.getCoursewaresList()
      //获取软件列表
      this.getSoftwaresList()
    },
    methods: {
      //获取资料列表
      getMaterialsList(pageNum=1, pageSize=20){
        this.isLoading = true
        let params = {
          pageNum: pageNum,
          pageSize: pageSize,
          categoryId: 1,
          userName: window.localStorage.getItem('userName'),
        }
        getUserCollectList(params)
          .then((res) => {
            if (res.status == 200){
              this.materialList = res.data.list
              this.materialPagination.total = res.data.total
              this.isLoading = false
            }
            else{
              this.$message.info(res.msg)
            }
          })
      },
      //获取课件列表
      getCoursewaresList(pageNum=1, pageSize=20){
        this.isFanLoading = true
        let params = {
          pageNum: pageNum,
          pageSize: pageSize,
          categoryId: 2,
          userName: window.localStorage.getItem('userName'),
        }
        getUserCollectList(params)
          .then((res) => {
            if (res.status == 200){
              this.coursewareList = res.data.list
              this.coursewarePagination.total = res.data.total
              this.isFanLoading = false
            }
            else{
              this.$message.info(res.msg)
            }
          })
      },
      //获取软件列表
      getSoftwaresList(pageNum=1, pageSize=20){
        this.isFanLoading = true
        let params = {
          pageNum: pageNum,
          pageSize: pageSize,
          categoryId: 3,
          userName: window.localStorage.getItem('userName'),
        }
        getUserCollectList(params)
          .then((res) => {
            if (res.status == 200){
              this.softwareList = res.data.list
              this.softwarePagination.total = res.data.total
              this.isFanLoading = false
            }
            else{
              this.$message.info(res.msg)
            }
          })
      },
      //取消关注粉丝
      cancelFollowed(item) {
        let params = {
          followUserName: window.localStorage.getItem('userName'),
          followedUserName: item.resourceUserName
        }
        cancelFollowResource(params)
          .then((res) => {
            if (res.status == 200){
              this.$message.success('取消关注成功！')
              //获取资料列表
              this.getMaterialsList()
              //获取课件列表
              this.getCoursewaresList()
              //获取软件列表
              this.getSoftwaresList()
            }
            else{
              this.$message.info(res.msg)
            }
          })
      },
      //取消收藏
      cancelCollect(item) {
        let params = {
          resourceId: item.resourceId,
          userName: window.localStorage.getItem('userName')
        }
        cancelCollectResource(params)
          .then((res) => {
            if (res.status == 200){
              this.$message.success('取消收藏成功！')
              //获取资料列表
              this.getMaterialsList()
              //获取课件列表
              this.getCoursewaresList()
              //获取软件列表
              this.getSoftwaresList()
            }
            else{
              this.$message.info(res.msg)
            }
          })
      },
      selectStyle(){

      }
    }
  }
</script>

<style lang="less" scoped>
  .flex{
    display: flex;
    flex-direction: row;
  }
  .container{
    width: 1032px;
    height: 100%;
    background-color: #ffffff;
    border-radius: 4px;
    border: 1px solid #eeeeee;
    padding: 5px 13px;
  }
  .contain-header{
    justify-content: space-between;
    align-items: center;
  }
  .contain-title{
    font-family: MicrosoftYaHei;
    font-size: 18px;
    font-weight: bold;
    font-stretch: normal;
    letter-spacing: 1px;
    color: #1bcbb4;
    margin-top: 10px;
  }
  .tag-page{
    margin-top: 30px;
    text-align: left;
  }
  .avatar{
    border: 2px solid #1bcbb4;
    width: 80px;
    height: 80px;
  }
  .title{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin-top: 5px;
  }
  .title-text{
    font-family: MicrosoftYaHei;
    font-size: 15px;
    font-weight: 600;
    color: #222222;
    width: 152px;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .title-width{
    width: 170px;
  }
  .collect{
    align-items: center;
  }
  .collect-text{
    font-family: MicrosoftYaHei;
    font-size: 12px;
    color: #666666;
    margin-left: 5px;
  }
  .item-footer{
    font-family: MicrosoftYaHei;
    font-size: 12px;
    color: #666666;
    border-top: 1px dashed #eaeaea;
    justify-content: space-between;
    padding: 5px;
  }
  .header{

  }
  .course{
    font-family: MicrosoftYaHei;
    font-size: 12px;
    color: #999999;
    margin-left: 15px;
    margin-right: 15px;
  }
  .followed{
    margin-left: 98px;
    margin-top: -10px;
  }
  .image{
    width: 100%;
    height: 128px;
  }
  .more{
    display: inline-block;
    font-size: 13px;
    cursor: pointer;
  }
  .more-list{
    margin-top: -10px;
    margin-bottom: 5px;
    text-align: right;
  }
  .more:hover{
    color: #1bcbb4;
  }
  .column-space{
    margin-top: 12px;
  }
  .list-item{
    border-radius: 4px;
    border: solid 1px #eeeeee;
    padding: 5px;
    cursor: pointer;
  }
  .list-item:hover{
    border: solid 1px #1bcbb4;
    box-shadow: 2px 2px 20px #dddddd;
  }
  .decoration{
    font-size: 12px;
    color: #666666;
    text-align: left;
    margin-top: 10px;
    margin-bottom: 20px;
  }
  .footer-presenter{
    color: #222222;
    font-weight: 600;
  }
  .tag-vedio{
    text-align: center;
  }
  .hot-img{
    position: absolute;
    top: 0px;
    left: 17px;
  }
  .nav-icon{
    color: #999999;
    font-size: 12px;
  }

  //课件
  .kejian {
    .flex{
      display: flex;
      flex-direction: row;
    }
    .header{
      justify-content: space-between;
      align-items: center;
    }
    .column-space{
      margin-top: 12px;
    }
    .list-item{
      border-radius: 4px;
      border: solid 2px #eeeeee;
      padding: 5px;
      cursor: pointer;
      background-color: #ffffff;
    }
    .list-item:hover{
      border: solid 2px #1bcbb4;
      box-shadow: 2px 2px 20px #dddddd;
    }
    .hot-img{
      position: absolute;
      top: 0px;
      left: 17px;
    }

    .title-text-live{
      font-size: 15px;
      font-weight: 600;
      color: #222222;
      width: 145px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      margin-top: 5px;
    }

    .collect{
      align-items: center;
    }
    .collect-text{
      font-family: MicrosoftYaHei;
      font-size: 11px;
      color: #666666;
      margin-left: 3px;
    }
    .item-footer{
      font-family: MicrosoftYaHei;
      font-size: 12px;
      color: #666666;
      border-top: 1px dashed #eaeaea;
      justify-content: space-between;
      padding: 5px;
    }
    .header{

    }
    .image{
      width: 100%;
      /*height: 128px;*/
    }

    .icon-star{
      font-size: 13px;
    }
    .margin-live{
      margin-left: 10px;
    }
    .living{
      font-size: 12px;
      color: #f91a44;
      font-weight: 600;
    }
    .item-title-live{
      margin-left: 4px;
      text-align: left;
    }
    .footer-presenter-live{
      font-size: 12px;
      color: #222222;
      margin-top: 20px;
    }
  }

  //软件
  .software {
    .flex{
      display: flex;
      flex-direction: row;
    }
    .header{
      /*justify-content: space-between;*/
      align-items: center;
    }
    .column-space{
      margin-top: 12px;
    }
    .list-item{
      border-radius: 4px;
      border: solid 2px #eeeeee;
      padding: 5px;
      cursor: pointer;
      background-color: #ffffff;
    }
    .list-item:hover{
      border: solid 2px #1bcbb4;
      box-shadow: 2px 2px 20px #dddddd;
    }
    .decoration{
      font-size: 12px;
      color: #666666;
      text-align: left;
      margin-top: 10px;
      margin-bottom: 20px;
    }
    .footer-presenter{
      color: #222222;
      font-weight: 600;
    }
    .hot-img{
      position: absolute;
      top: 0px;
      left: 17px;
    }
    .item-title{
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      margin-top: 5px;
    }
    .title-text{
      font-size: 15px;
      font-weight: 600;
      color: #222222;
      width: 150px;
      text-align: left;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .title-width{
      width: 155px;
    }
    .collect{
      align-items: center;
    }
    .collect-text{
      font-family: MicrosoftYaHei;
      font-size: 11px;
      color: #666666;
      margin-left: 3px;
    }
    .item-footer{
      font-family: MicrosoftYaHei;
      font-size: 12px;
      color: #666666;
      border-top: 1px dashed #eaeaea;
      justify-content: space-between;
      padding: 5px;
    }
    .flex-between{
      justify-content: space-between;
      justify-items: center;
    }
    .image{
      width: 100px;
      /*height: 128px;*/
    }
    .icon-star{
      font-size: 13px;
    }
    .title-text-live {
      margin-left: 20px;
      font-size: 15px;
      font-weight: bold;
    }
    .item-title-live {
      width: 100%;
    }
    .footer-presenter-live {
      text-align: left;
      margin-left: 20px;
    }
  }
  //资料
  .file {
    .flex{
      display: flex;
      flex-direction: row;
    }
    .header{
      justify-content: space-between;
      align-items: center;
    }
    .column-space{
      margin-top: 12px;
    }
    .list-item{
      border-radius: 4px;
      border: solid 2px #eeeeee;
      padding: 5px;
      cursor: pointer;
      background-color: #ffffff;
    }
    .list-item:hover{
      border: solid 2px #1bcbb4;
      box-shadow: 2px 2px 20px #dddddd;
    }
    .decoration{
      font-size: 12px;
      color: #666666;
      text-align: left;
      margin-top: 10px;
      margin-bottom: 5px;
    }
    .footer-presenter{
      color: #222222;
      font-weight: 600;
    }
    .hot-img{
      position: absolute;
      top: 0px;
      left: 17px;
    }
    .item-title{
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      margin-top: 5px;
    }
    .title-text{
      font-size: 15px;
      font-weight: 600;
      color: #222222;
      width: 150px;
      text-align: left;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .title-width{
      width: 155px;
    }
    .collect{
      align-items: center;
    }
    .collect-text{
      font-family: MicrosoftYaHei;
      font-size: 11px;
      color: #666666;
      margin-left: 3px;
    }
    .item-footer{
      font-family: MicrosoftYaHei;
      font-size: 12px;
      color: #666666;
      border-top: 1px dashed #eaeaea;
      justify-content: space-between;
      padding: 5px;
    }
    .public-time{
      text-align: right;
      margin-top: 10px;
    }
    .image{
      width: 100%;
      /*height: 128px;*/
    }
    .icon-star{
      font-size: 13px;
    }
    .detail-style {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 3;/*想省略几行就写几*/
      -webkit-box-orient: vertical;
      text-indent: 2em;
      height: 50px;
    }
  }

  /* 覆盖默认的ant样式 */
  .tag-vedio{
    :global(.ant-tabs-nav .ant-tabs-tab){
      font-family: MicrosoftYaHei;
      font-size: 17px;
      padding: 8px 1px;
      font-weight: 500;
    }
    :global(.ant-tabs-ink-bar){
      height: 4px;
    }
  }


</style>
